import http from "../../utils/http"
// 导入 licia 提供的节流函数
import { throttle } from 'miniprogram-licia'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Banner:[],
    hotList:[],
    flag:true,
    bigList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad () {
    this.getNotices()
    this.getrecommend()
    this.getBigList()
    this.getMoreVisitor = throttle(() => {
      // 创建了节流函数
      if(!this.data.hasmore) return wx.utils.toast('到底了~~~')
      this.getBigList(++this._page)

    }, 100)
  },
 // 调用公告列表接口
  async getNotices() {
    // 请求接口
    const res = await http.get('/index/index')
    // console.log(res.data.showBanner);
    // 渲染数据
    this.setData({Banner:res.data.banner})
    // console.log(res);
  },
 
  async getrecommend(){
    const res = await http.get('/index/hot')
   //  console.log(res);
   // this.data.hotList = res.data.list
    this.setData({hotList:res.data.list})
 
   },


   async getBigList(page = 1, limit = 10){
    const data = await http.get('/index/new',{limit,page}
    )
    console.log(data);
    // this.data.bigList = data.data.list.data
    this.setData(
      {
        bigList:this.data.bigList.concat(data.data.list.data),
        hasmore:page < data.data.list.totalPages
      
      }
      )
     
    this._page = page 
   }
 
 
})